#include "lab52.h"

int CurrentCnt = 0;

int main()
{
    int input = 0;

    GoodsList Head;
    GoodsList* pHead = &Head;
    init_list(&pHead);

    while (true)
    {
        printf("\n1.显示所有商品的信息\n");
        printf("2.修改某个商品的信息\n");
        printf("3.插入某个商品的信息\n");
        printf("4.删除某个商品的信息\n");
        printf("5.查找某个商品的信息\n");
        printf("6.商品存盘并退出系统\n");
        printf("7.对商品价格进行排序\n");
        printf("8.(慎用)删除所有内容\n");

        scanf("%d", &input);
        switch (input)
        {
            case 1:
                output_all_items(pHead);
                break;
            case 2:
            {
                char goods_id[MAX_ID_LEN];
                printf("请输入要修改的商品 id:>");//可以加上跳转查看的功能
                scanf("%s", goods_id);
                if (search_item(pHead, goods_id) == NULL)
                {
                    printf("此商品不存在\n");
                }
                else
                {
                    change_item(pHead, goods_id, read_goods_info());
                }
                break;
            }
            case 3:
            {
                int choice;

                printf("请输入要插入的位置(0 表示插入末尾，1 表示插入开头，其余的表示插入到第 x 个节点):>");
                scanf("%d", &choice);
                insert_item(pHead, read_goods_info(), choice);
                break;
            }
            case 4:
            {
                char goods_id[MAX_ID_LEN];
                printf("请输入要删除的商品的 id:>");
                scanf("%s", goods_id);
                delete_item(pHead, goods_id);
                break;
            }
            case 5:
            {
                char goods_id[MAX_ID_LEN];
                printf("请输入要查询的商品的 id:>");
                scanf("%s", goods_id);
                search_item(pHead, goods_id);
                break;
            }
            case 6:
                save_to_file(pHead);
                goto end;
            case 7:
                bubble_sort(pHead);
                break;
            case 8:
                destory_list_and_file(&pHead);
                break;
            default:
                printf("程序不存盘并退出系统\n");
                destory_list(&pHead);
                goto end;
        }
    }

end:
    return 0;
}
